import request from '@/utils/request'
import type {RoleResponseData,RoleData,MenuResponseData} from './type'
//接口地址
enum API {
    ALLROLE_URL = '/admin/acl/role/',
    ADDROLE_URL = '/admin/acl/role/save',
    UPDATEROLE_URL = '/admin/acl/role/update',
    ALLPERMISSION_URL = '/admin/acl/permission/toAssign/',
    SETPERMISSION_URL = '/admin/acl/permission/doAssign/?',
    REMOVEROLE_URL = '/admin/acl/role/remove/'
}
//获取列表
export const reqAllRoleList = (page:number,limit:number,username:string)=>{
    return request.get<any,RoleResponseData>(API.ALLROLE_URL+`${page}/${limit}/?username=${username}`)
}  
//新增和编辑
export const reqAddOrUpdateRole = (data:RoleData)=>{
    if(data.id){
        return request.put<any,any>(API.UPDATEROLE_URL,data)
    }else{
        return request.post<any,any>(API.ADDROLE_URL,data)
    }
}  
//获取分配菜单列表
export const reqAllMenuList = (roleId:number)=>{
    return request.get<any,MenuResponseData>(API.ALLPERMISSION_URL + roleId)
}
//分配权限
export const reqSetPermission = (roleId:number,permissionId:number[])=>{
    return request.post(API.SETPERMISSION_URL + `${roleId}&permissionId=${permissionId}`)
}
//删除
export const reqRemoveRole = (roleId:number)=>{
    return request.delete(API.REMOVEROLE_URL + roleId)
}